package com.liu.stockmarket.ui.self

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.model.Stock
import com.liu.stockmarket.utils.getString
import com.liu.stockmarket.utils.percentBg
import java.math.BigDecimal

class SelfAdapter : BaseQuickAdapter<SelfAdapter.Item, BaseViewHolder>(R.layout.item_self) {


    override fun convert(holder: BaseViewHolder, item: Item) {
        holder.setText(R.id.tv_name, item.name)
            .setText(R.id.tv_code, item.code)
            .setText(R.id.tv_type, item.stockType?.text)
            .setText(R.id.tv_now_price, item.nowPrice.getString())

        with(holder.getView<TextView>(R.id.tv_now_price_percent)) {
            this.percentBg(context, item.upOrDownPercent)
        }
    }

    data class Item(
        val selfId: Long? = null,
        val code: String,
        val name: String,
        val type: Stock.TransactionExchange?,
        val stockType: Stock.StockType?,
        val nowPrice: BigDecimal,
        /**
         * 涨跌幅
         */
        val upOrDownMoney: BigDecimal,
        val upOrDownPercent: BigDecimal
    )


}